package com.ada.apps;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import com.ada.iwan.utils.RpcUtils;
import com.ada.user.entity.UserInfo;
import com.ada.user.service.UserInfoService;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class JxlApps {

	public static void main(String[] args) throws BiffException, IOException {
		// TODO Auto-generated method stub
		List<UserInfo> list = new ArrayList<UserInfo>();
		Workbook rwb = null;
		Cell cell = null;

		// 创建输入流
		InputStream stream = new FileInputStream("d:\\新增通讯录.xls");

		// 获取Excel文件对象
		rwb = Workbook.getWorkbook(stream);

		// 获取文件的指定工作表 默认的第一个
		Sheet sheet = rwb.getSheet(0);

		// 行数(表头的目录不需要，从1开始)
		for (int i = 1; i < sheet.getRows(); i++) {
            UserInfo user=new UserInfo();
			// 创建一个数组 用来存储每一列的值

			// 列数
				// 获取第i行，第j列的值
				//cell = sheet.getCell(j, i);
				user.setUsername(sheet.getCell(1, i).getContents().trim());
				user.setName(sheet.getCell(0, i).getContents().trim());
				user.setRealName(sheet.getCell(0, i).getContents().trim());
				user.setPhone(sheet.getCell(1, i).getContents().trim());
				user.setEmail(sheet.getCell(2, i).getContents().trim());
				user.setPlainPassword("ccnc.cc123");

			// 把刚获取的列存入list
			list.add(user);
		}
		UserInfoService service=RpcUtils.get(UserInfoService.class);
		for (int i = 0; i < list.size(); i++) {
			UserInfo str =  list.get(i);
			System.out.println(str);
			UserInfo u=	service.reg(str);
			try {
				System.out.println(u.getId());
			} catch (Exception e) {
				// TODO: handle exception
			}
		}
	}

}
